﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MiniCalc
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        
        MiniCalc.Calculator.CalcOperation op = MiniCalc.Calculator.CalcOperation.Add;

        private void EqualsButton_Click(object sender, EventArgs e)
        {
            try
            {
                //if (AddRButton.Checked)
                //{
                //    op = Calculator.CalcOperation.Add;
                //}
                //else
                //{
                //    op = Calculator.CalcOperation.Subtract;
                //}
                Calculator calc = new Calculator();
                Result.Text = calc.Calculate((int)NumberA.Value, op, 
                    (int)NumberB.Value).ToString();
            }
            catch (ResultOutOfRangeException)
            {
                Result.Text = "Out of Range";
            }
            catch (NegativeParameterException)
            {
                Result.Text = "Negatives not allowed";
            }
            

            //try
            //{
            //    Calculator calc = new Calculator();
            //    Result.Text = (calc.Add((int)NumberA.Value, (int)NumberB.Value).ToString());
            //}
            //catch (ResultOutOfRangeException)
            //{
            //    Result.Text = "Out of Range";
            //}
        }

        private void AddRButton_CheckedChanged(object sender, EventArgs e)
        {
            if (AddRButton.Checked)
            {
                op = Calculator.CalcOperation.Add;
            }
        }

        private void SubtractRButton_CheckedChanged(object sender, EventArgs e)
        {
            if (SubtractRButton.Checked)
            {
                op = Calculator.CalcOperation.Subtract;
            }
        }
    }
}
